package com.hc.conferencecheck.controller;

import com.alibaba.fastjson.JSONObject;
import com.hc.conferencecheck.entity.ResultMsg;
import com.hc.conferencecheck.entity.ResultStatusCode;
import com.hc.conferencecheck.service.AttendRecordBranchService;
import com.hc.conferencecheck.service.AttendRecordService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 用于会议申请记录的controller
 */
@RestController
@RequestMapping("/attendRecordController")
public class AttendRecordController {
    @Resource
    private AttendRecordService attendRecordServiceImpl;
    @Resource
    private AttendRecordBranchService attendRecordBranchServiceImpl;

    /**
     * 审核页面查询所有的未通过申请记录（未通过，审核中）
     */
    @RequestMapping("/selectAllAttendRecordUnApproved")
    public ResultMsg selectAllAttendRecordUnApproved(String param) {
        Map params = (Map) JSONObject.parseObject(param);
        //获取参数，参数非空判断
        Object pageNumberObj = params.get("pageNumber");
        if (pageNumberObj == null) {
            return new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.EORROR.getMsg(), "分页参数不可为空");
        }
        ResultMsg resultMsg = attendRecordServiceImpl.selectAllAttendRecordUnApproved(params);
        return resultMsg;
    }

    /**
     * 修改会议分会场的签到状态
     */
    @RequestMapping("/editBranchAddressStatus")
    public ResultMsg editBranchAddressStatus(String param) {
        Map params = (Map) JSONObject.parseObject(param);
        //获取参数，参数非空判断
        Object recordIdObj = params.get("recordId");
        if (recordIdObj == null) {
            return new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.EORROR.getMsg(), "记录ID不可为空");
        }
        Object statusObj = params.get("status");
        if (statusObj == null) {
            return new ResultMsg(ResultStatusCode.EORROR.getCode(), ResultStatusCode.EORROR.getMsg(), "状态码不可为空");
        }
        //传递参数
        int recordId = Integer.parseInt(recordIdObj.toString());
        int status = Integer.parseInt(statusObj.toString());
        ResultMsg resultMsg = attendRecordBranchServiceImpl.editBranchAddressStatus(recordId, status);
        return resultMsg;
    }

    /**
     * 更改会议申请记录的审核状态
     */
    @RequestMapping("/editIsApproved")
    public ResultMsg editIsApproved(String param) {
        Map params = (Map) JSONObject.parseObject(param);
        ResultMsg resultMsg = attendRecordServiceImpl.editIsApproved(params);
        return resultMsg;
    }

    /**
     * 查询所有的会议申请记录,所有已通过，或者未通过，或者所有的会议申请记录
     */
    @RequestMapping("/selectAllAttendRecordIsApproved")
    public ResultMsg selectAllAttendRecordIsApproved(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = attendRecordServiceImpl.selectAllAttendRecordIsApproved(params);
        return resultMsg;
    }

    /**
     * 查询用户所有会议申请记录
     */
    @RequestMapping("/selectConventionerAttendRecord")
    public ResultMsg selectConventionerAttendRecord(String param) {
        Map params = (Map) JSONObject.parseObject(param);
        ResultMsg resultMsg = attendRecordServiceImpl.selectConventionerAttendRecord(params);
        return resultMsg;
    }

    /**
     * 更改会议申请记录的签到状态
     */
    @RequestMapping("/editSignCode")
    public ResultMsg editSignCode(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = attendRecordServiceImpl.editSignCode(params);
        return resultMsg;
    }

    /**
     * 根据会议申请记录ID，查询会议申请记录
     */
    @RequestMapping("/selectAttendRecordByPrimaryKey")
    public ResultMsg selectAttendRecordByPrimaryKey(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = attendRecordServiceImpl.selectAttendRecordByPrimaryKey(params);
        return resultMsg;
    }

    /**
     * 查询某用户某种状态的申请记录
     */
    @RequestMapping("/selectConferencesByConventionerId")
    public ResultMsg selectConferencesByConventionerId(@RequestBody Map<String, Object> params) {
        ResultMsg resultMsg = attendRecordServiceImpl.selectConferencesByConventionerId(params);
        return resultMsg;
    }
}
